﻿using Bogus;
using RescueApp.Models;

public static class NewFakers
{
    public static string GeneratePrefixedString(this Faker faker, string prefix, int length)
    {
        string randomString = faker.Random.String2(length, "0123456789");
        return $"{prefix}{randomString}";
    }
}

public class RescueSystemFakers
{
    private Faker<RescueApply> _rescueApplyFaker;
    private Faker<RescueDispatch> _rescueDispatchFaker;

    public RescueSystemFakers()
    {
        // 初始化 RescueApply Faker
        _rescueApplyFaker = new Faker<RescueApply>()
            .RuleFor(ra => ra.RescueID, f => 0) // 设置为 0，让数据库自动生成
            .RuleFor(ra => ra.VehicleLicensePlate, f => f.GeneratePrefixedString("ABC", 6))
            .RuleFor(ra => ra.CarType, f => f.PickRandom(new[] { "私家车", "货车", "公交车" }))
            .RuleFor(ra => ra.DriverIdentification, f => f.Random.String2(18, "0123456789"))
            .RuleFor(ra => ra.ApplicantPhone, f => f.Phone.PhoneNumber("1#########"))
            .RuleFor(ra => ra.RescueLocation, f => f.Address.City())
            .RuleFor(ra => ra.RepairDestination, f => f.PickRandom(new[] { "4S店", "维修厂" }))
            .RuleFor(ra => ra.ApplicationDate, f => f.Date.Past(1));

        // 初始化 RescueDispatch Faker
        _rescueDispatchFaker = new Faker<RescueDispatch>()
            .RuleFor(rd => rd.DispatchID, f => 0) // 设置为 0，让数据库自动生成
            .RuleFor(rd => rd.DispatchDriver, f => f.Name.FullName())
            .RuleFor(rd => rd.DispatchVehicleLicense, f => f.GeneratePrefixedString("救援车-", 5))
            .RuleFor(rd => rd.ArrivalTime, f => f.Date.Future(1, DateTime.Now.AddDays(24)))
            .RuleFor(rd => rd.MalfunctionCause, f => f.Lorem.Sentence())
            .RuleFor(rd => rd.RescueCost, (f, rd) => (float)f.Finance.Amount(100, 1000));
    }

    

    public Faker<RescueApply> RescueApplyFaker => _rescueApplyFaker;
    public Faker<RescueDispatch> RescueDispatchFaker => _rescueDispatchFaker;
}